PATHMac OS 8 and 9 Developer Documentation > Interapplication Communication > AppleScript for Scripters >

AppleScript Language Guide

   

Open Handlers

All Mac OS applications can respond to the Open command, even if they aren't scriptable. The Finder sends an Open command to an application whenever the user drags file, folder, or disk icons over the application's icon and releases the mouse button. The Open command is sent even if the application is already running.

Like any other application, a script application receives an Open command whenever the user drags file, folder, or disk icons over the application's icon. If the script in the script application includes an Open handler, the statements within the handler run when the application receives the Open command. The Open handler takes a single parameter; when the handler is called, the value of that parameter is a list of all the items whose icons were dropped on the script application's icon. (Each item in the list is an alias; you can convert it to a pathname by using as string .)

For example, this Open handler makes a list of the pathnames of all items dropped on the script application's icon and saves them in a specified AppleWorks document:

on open names
    set listOfPaths to "" -- Start with empty string.
    repeat with i in names
        -- Get the name and append a return character so that
        --  each name starts on a separate line.
        set iPath to (i as string)
        set listOfPaths to listOfPaths & iPath & return
    end repeat
    -- Open document and replace current first paragraph with list.
    tell application "AppleWorks"
        open file "Hard Disk:File List"
        tell front document
            select first paragraph of text body
            set selection to listOfPaths
        end tell
        close front document saving ask
    end tell
    return
end open

Files, folders, or disks are not moved, copied, or affected in any way when their icons are dragged and dropped over a script application's icon. The Finder just gets a list of their identities and sends that list to the script application as the direct parameter of the Open event. Of course, the script in the script application could easily tell the Finder to move, copy, or otherwise manipulate the items. The script could also ask the user to specify a filename for saving the list of pathnames.

Note

Due to a known limitation of system software, you can't drop icons on an icon for a script application that's stored on a floppy disk.

You can also run an Open handler by sending a script application the Open command. For details, see Calling a Script Application From a Script.


© 1999 Apple Computer, Inc. – (Last Updated 21 May 99)